<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../vue.js"></script>
    <style>
      .active {
        background-color: lightblue;
      }
      .error {
        color: red;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <!-- <p class="test">一段文字</p> -->
      <p v-bind:class="condition? 'active': ''">一段文字</p>
      <p v-bind:class="{active: condition}">一段文字</p>

      <hr />

      <p v-bind:class="(condition? 'active': '') + (isError? ' error': '')">
        一段文字
      </p>
      <p class="static" v-bind:class="{active: condition, error: isError}">
        一段文字
      </p>

      <!-- 对象表示法 {类名：条件} -->

      <hr />
      <!-- 绑定的数据对象不必内联定义在模板里： -->
      <p class="static" v-bind:class="obj">一段文字</p>

      <hr />

      <p v-bind:class="[a, b]">数组语法</p>

      <hr />

      <!-- <p style="color: red; font-size: 12px">style样式</p> -->
      <p :style="{color: c, fontSize: n+'px'}">style样式</p>

      <p :style="[obj1, obj2]">style样式</p>
    </div>

    <script>
      var vm = new Vue({
        el: "#app",
        data: {
          condition: true,
          isError: false,
          //   obj: { active: true, error: true },

          a: "aaa",
          b: "bbb",
          c: "blue",
          n: 20,

          obj1: {
            color: "red",
          },
          obj2: {
            background: "green",
          },
        },
        computed: {
          obj: function () {
            return { active: this.condition, error: this.isError };
          },
        },
      });
    </script>
  </body>
</html>
